use rand::Rng;
use std::{io, cmp::Ordering};
fn main() {
    // 生成一个随机数
    let secert_num = rand::thread_rng().gen_range(1..=100);
    println!("你的随机数位{secert_num}");
    // 循环
    loop {
        // 声明一个string
        let mut guess = String::new();
        // 读取命令行参数
        io::stdin().read_line(&mut guess).expect("请输入正确的值");
        println!("你输入的为{guess}");
        // 比较大小
        let guess: u32 = guess.trim().parse().expect("输入的值有误");
        println!("转换后的为{guess}");
        match guess.cmp(&secert_num) {
            Ordering::Less => println!("To Small"),
            Ordering::Equal => {
                println!("猜中了");
                break;
            },
            Ordering::Greater => println!("To Large"),
        }
    }
}
